﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using Xom.Attributes;
using Xom.Elements;

namespace Xom.UnitTests.Mocks
{
    public class SimpleXmlTestContainerObject : XomElement
    {
        private IList<SimpleXmlTestObject> _items;

        [XomBinding("simple", false, true, 0, typeof(SimpleXmlTestObject))]
        public IList<SimpleXmlTestObject> Items
        {
            get { return _items; }
            set
            {
                _items = value;
                RaisePropertyChanged("Items");
            }
        }

        public SimpleXmlTestContainerObject()
        {
            _items = new ObservableCollection<SimpleXmlTestObject>();
            //NotifyCollectionChanged 
            INotifyCollectionChanged notifylist = _items as INotifyCollectionChanged;
            notifylist.CollectionChanged += OnCollectionChanged;
        }

        private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
        {
            RaiseXomCollectionChanged(this, "Items", notifyCollectionChangedEventArgs);
        }
    }

    public class SimpleXmlTestObject : XomElement
    {
        private string _name;
        private uint _id;
        private bool? _isActive;
        private double? _value;
        private SimpleSubXmlTestObject _control;

        [XomBinding("name", true, false, 10)]
        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                RaisePropertyChanged("Name");
            }
        }

        [XomBinding("Id", true, true, 20)]
        public uint Id
        {
            get { return _id; }
            set
            {
                _id = value;
                RaisePropertyChanged("Id");
            }
        }

        [XomBinding("Active", false, false, 80)]
        public bool? IsActive
        {
            get { return _isActive; }
            set
            {
                _isActive = value;
                RaisePropertyChanged("IsActive");
            }
        }

        [XomBinding("Value", false, false, 70)]
        public double? Value
        {
            get { return _value; }
            set
            {
                _value = value;
                RaisePropertyChanged("Value");
            }
        }

        [XomBinding("sub", false, false, 100, typeof(SimpleSubXmlTestObject))]
        public SimpleSubXmlTestObject Control
        {
            get { return _control; }
            set
            {
                _control = value;
                RaisePropertyChanged("Control");
            }
        }
    }

    public class SimpleSubXmlTestObject : XomElement
    {
        private string _info;
        private string _note;
        private int? _index;

        [XomBinding("", false, true, 100)]
        public string Info
        {
            get { return _info; }
            set
            {
                _info = value;
                RaisePropertyChanged("Info");
            }
        }

        [XomBinding("index", true, false, 10)]
        public int? Index
        {
            get { return _index; }
            set
            {
                _index = value;
                RaisePropertyChanged("Index");
            }
        }

        [XomBinding("note", true, false, 20)]
        public string Note
        {
            get { return _note; }
            set
            {
                _note = value;
                RaisePropertyChanged("Note");
            }
        }
    }

    public class StringTestObject : XomElement
    {
        private string _optAttribute;
        private string _optAttribute2;
        private string _reqAttribute;
        private string _optElement;
        private string _optElement2;
        private string _reqElement;

        [XomBinding("optAtt", true, false, 10)]
        public string OptAttribute
        {
            get { return _optAttribute; }
            set
            {
                _optAttribute = value;
                RaisePropertyChanged("OptAttribute");
            }
        }

        [XomBinding("reqAtt", true, true, 20)]
        public string ReqAttribute
        {
            get { return _reqAttribute; }
            set
            {
                _reqAttribute = value;
                RaisePropertyChanged("ReqAttribute");
            }
        }

        [XomBinding("optAtt2", true, false, 30)]
        public string OptAttribute2
        {
            get { return _optAttribute2; }
            set
            {
                _optAttribute2 = value;
                RaisePropertyChanged("OptAttribute2");
            }
        }

        [XomBinding("optElement", false, false, 100)]
        public string OptElement
        {
            get { return _optElement; }
            set
            {
                _optElement = value;
                RaisePropertyChanged("OptElement");
            }
        }

        [XomBinding("reqElement", false, true, 200)]
        public string ReqElement
        {
            get { return _reqElement; }
            set
            {
                _reqElement = value;
                RaisePropertyChanged("ReqElement");
            }
        }

        [XomBinding("optElement2", false, false, 300)]
        public string OptElement2
        {
            get { return _optElement2; }
            set
            {
                _optElement2 = value;
                RaisePropertyChanged("OptElement2");
            }
        }
    }

    public class SimpleListContainerObject : XomElement
    {
        private IList<string> _valueList;

        [XomBinding("Value", false, true, 0)]
        public IList<string> ValueList
        {
            get { return _valueList; }
            set
            {
                _valueList = value;
                RaisePropertyChanged("Value");
            }
        }

        public SimpleListContainerObject()
        {
            _valueList = new ObservableCollection<string>();
            //NotifyCollectionChanged 
            INotifyCollectionChanged notifylist = _valueList as INotifyCollectionChanged;
            notifylist.CollectionChanged += OnCollectionChanged;
        }

        private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
        {
            RaiseXomCollectionChanged(this, "ValueList", notifyCollectionChangedEventArgs);
        }
    }
}
